{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 百度AI开发平台\n",
    "\n",
    "百度AI开发平台链接:https://ai.baidu.com/\n",
    "\n",
    "百度AI平台当前提供语音合成、语音识别、图像识别、文字识别和自然语言处理等人工智能处理接口，同时提供一定量的试用体验，便于我们免费利用百度AI开发平台实现验证我们的想法。\n",
    "\n",
    "最重要的是，要注册一个百度AI开发平台的账户。因为试用体验是有限制的，您使用我的账户体验可能会存在试用量已用完，您只需注册一个百度账户，按照我的教程，建立一个自己的体验应用，将体验的API注册码更换为自己的API注册码即可解决试用量不足的问题。\n",
    "\n",
    "百度AI开发平台注册链接:https://login.bce.baidu.com/?account=&redirect=http%3A%2F%2Fconsole.bce.baidu.com%2F%3Ffromai%3D1#/aip/overview"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 树莓派4B\n",
    "\n",
    "Raspberry Pi(中文名为“树莓派”,简写为RPi，(或者RasPi / RPI)  树莓派由注册于英国的慈善组织“Raspberry Pi 基金会”开发，只有信用卡大小的微型电脑，其系统基于Linux。\n",
    "\n",
    "树莓派官网:https://www.raspberrypi.org/\n",
    "\n",
    "树莓派实验室(国内很好的树莓派资料网站):https://shumeipai.nxez.com/\n",
    "\n",
    "树莓派4B介绍:https://shumeipai.nxez.com/2019/06/24/raspberry-pi-4-on-sale-now.html"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Raspberry Pi OS——树莓派官方操作系统\n",
    "\n",
    "Raspbian 是一个基于 Debian 的 Linux 发行版，专门用于 Raspberry Pi，它是Raspberry 用户的完美通用操作系统。\n",
    "\n",
    "Raspberry Pi OS官方地址:https://www.raspberrypi.org/downloads/raspberry-pi-os/\n",
    "\n",
    "本课程使用的操作系统是基于官方Raspberry Pi OS系统，进行深度定制，安装了本课程所需的软件和课件。\n",
    "\n",
    "只要有一台计算机、一张SD卡、一个SD卡读卡器，下载课程指定的镜像，就可以进行系统安装了。别担心，安装很简单，只需三步即可完成。\n",
    "\n",
    "安装详情见《课程配套的树莓派系统安装说明》。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "######################################################\n",
    "#\n",
    "# 课程助理——智能小派来讲课,原来不止一个小派，声音变了,选择本cell，按shirt+enter键运行本模块\n",
    "#\n",
    "######################################################\n",
    "\n",
    "#!/usr/bin/env python\n",
    "# -*- coding: utf-8 -*-\n",
    "#\n",
    "# Copyright (c) 2020 Taste all Pi.\n",
    "#\n",
    "# Licensed under the GNU General Public License, Version 2.0 (the \"License\");\n",
    "# you may not use this file except in compliance with the License.\n",
    "# You may obtain a copy of the License at\n",
    "#\n",
    "#   http://www.gnu.org/licenses/gpl-2.0.html\n",
    "#\n",
    "# Unless required by applicable law or agreed to in writing, software\n",
    "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
    "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
    "# See the License for the specific language governing permissions and\n",
    "# limitations under the License.\n",
    "\n",
    "#导入标准库\n",
    "import sys\n",
    "import os\n",
    "\n",
    "#导入自定义库\n",
    "sys.path.append('../baidu_api_lib')\n",
    "from baidu_sound import baidu_word_2_sound\n",
    "\n",
    "\"\"\" 公开课的语音合成+人脸识别，可选更改为自己的api接口 \"\"\"\n",
    "APP_ID = '20558036'\n",
    "API_KEY = 'u3L19UyWw6Tmx8fvnkqufP4y'\n",
    "SECRET_KEY = '7VjAOyufSVY3IjlM6WV79xrhtivGwO8O'\n",
    "\n",
    "#阅读的内容\n",
    "rd_poem = [\"百度AI开发平台:\",\\\n",
    "            \"百度AI开发平台链接:https://ai.baidu.com/\",\\\n",
    "            \"百度AI平台当前提供语音合成、语音识别、图像识别、文字识别和自然语言处理等人工智能处理接口，同时提供一定量的试用体验，便于我们免费利用百度AI开发平台实现验证我们的想法。\",\\\n",
    "            \"最重要的是，要注册一个百度AI开发平台的账户。因为试用体验是有限制的，您使用我的账户体验可能会存在试用量已用完，您只需注册一个百度账户，按照我的教程，建立一个自己的体验应用，将体验的API注册码更换为自己的API注册码即可解决试用量不足的问题。\",\\\n",
    "            \"树莓派4B:\",\\\n",
    "            \"Raspberry Pi(中文名为“树莓派”,简写为RPi，(或者RasPi / RPI) 树莓派由注册于英国的慈善组织“Raspberry Pi 基金会”开发，只有信用卡大小的微型电脑，其系统基于Linux。\",\\\n",
    "            \"树莓派官网:\",\\\n",
    "            \"树莓派实验室(国内很好的树莓派资料网站):https://shumeipai.nxez.com/\",\\\n",
    "            \"树莓派4B介绍:\",\\\n",
    "            \"Raspberry Pi OS——树莓派官方操作系统:\",\\\n",
    "            \"Raspbian 是一个基于 Debian 的 Linux 发行版，专门用于 Raspberry Pi，它是Raspberry 用户的完美通用操作系统。\",\\\n",
    "            \"Raspberry Pi OS官方地址:\",\\\n",
    "            \"本课程使用的操作系统是基于官方Raspberry Pi OS系统，进行深度定制，安装了本课程所需的软件和课件。\",\\\n",
    "            \"只要有一台计算机、一张SD卡、一个SD卡读卡器，下载课程指定的镜像，就可以进行系统安装了。别担心，安装很简单，只需三步即可完成。\",\\\n",
    "            \"安装详情见《课程配套的树莓派系统安装说明》。\"]\n",
    " \n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #传入百度AI的参数\n",
    "        word_2_sound = baidu_word_2_sound(APP_ID, API_KEY, SECRET_KEY)\n",
    "            \n",
    "        #以迭代方式阅读\n",
    "        for one_poem in rd_poem:\n",
    "            #进行语音合成\n",
    "            word_2_sound.trans_word_to_sound(one_poem,'tst_sound.wav',sound_type = 4,sound_speed = 4)\n",
    "\n",
    "            #播放合成的语音\n",
    "            os.system('mplayer ' + 'tst_sound.wav')\n",
    "        \n",
    "        #删除临时文件    \n",
    "        os.remove('tst_sound.wav')\n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        #删除临时文件    \n",
    "        os.remove('tst_sound.wav')\n",
    "        \n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
